package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Supplier;
import cn.wolfcode.crm.mapper.SupplierMapper;
import cn.wolfcode.crm.query.PageResult;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.ISupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class SupplierServiceImpl implements ISupplierService {

    @Autowired
    private SupplierMapper mapper;

    public void insert(Supplier entity) {
        entity.setInputtime(new Date()); //设置当前时间为添加的时间
        mapper.insert(entity);
    }

    public void delete(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    public void update(Supplier entity) {
        mapper.updateByPrimaryKey(entity);
    }

    public Supplier get(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    public List<Supplier> list() {
        return mapper.selectAll();
    }

    public PageResult query(QueryObject qo) {
        int total = mapper.queryForCount(qo);
        List<Supplier> rows = mapper.queryForList(qo);
        return new PageResult(total,rows);
    }
}
